package com.gkj.controller;

import com.gkj.blog.business.service.TagsService;
import com.gkj.blog.business.vo.entity.TagsVo;
import com.gkj.blog.framework.object.ResponseVO;
import com.gkj.blog.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/tags")
public class TagsController {
    @Autowired
    TagsService tagsService;

    @RequestMapping("/listAll")
    public ResponseVO listAllTags(){
        return ResultUtil.success(null,tagsService.listAllTags());
    }

    @RequestMapping("/get/{id}")
    public ResponseVO getTag(@PathVariable("id") Long id){
        return ResultUtil.success(null,tagsService.select(id));
    }

    @RequestMapping("/add")
    public ResponseVO addTag(TagsVo tagsVo){
        tagsService.insert(tagsVo);
        return ResultUtil.success("添加标签"+tagsVo.getName()+"成功");
    }

    @RequestMapping("/remove")
    public ResponseVO removeTags(@RequestParam("ids[]") Long[] ids){
        for(Long id:ids){
            tagsService.delete(id);
        }
        return ResultUtil.success("成功删除"+ids.length+"条标签");
    }

    @RequestMapping("/edit")
    public ResponseVO editTag(TagsVo tagsVo){
        tagsService.update(tagsVo);
        return ResultUtil.success("标签修改成功");
    }
}
